package work20241126_27;

/**
 * @author zdl
 * @date 2024/11/27
 */
public class Demo35 {
    public static void main(String[] args) {
        //设计一个方法，求数组中所有相邻元素的和。
        int[] arr = {1, 2, 3, 4, 5};
        int[] s = sum(arr);
        for (int num: s){
            System.out.println(num);
        }
    }
    public static int[] sum(int[] arr){
        int[] sum = new int[arr.length -1];
        for (int i = 0; i < arr.length - 1; i++) {
             sum[i] = arr[i] + arr[i + 1];
//            System.out.println(arr[i] + "与" + arr[i + 1] + "的和为:" + sum);
        }
        return sum;
    }
}
